package domain;

import lombok.Data;
import lombok.ToString;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
/**
 * 简介说明: 用户实体
 *
 * @author: Half_Q_0115
 * @date: 2024/09/16 19:50:46
 * @version: 1.0
 */

@Data
@ToString
public class User {
    private String id;
    private String name;
    private String gender;
    private Integer college_id;
    private Integer identity;
    private String phone_number;
    private String password;

    public String newPassword(String password) {
        if (password == null || password.isEmpty()) {
            return "";
        }

        try {
            MessageDigest md = MessageDigest.getInstance("SHA-256");
            byte[] hashedPassword = md.digest(password.getBytes());
            StringBuilder sb = new StringBuilder();
            for (byte b : hashedPassword) {
                sb.append(String.format("%02x", b));
            }
            return sb.toString();
        } catch (NoSuchAlgorithmException e) {
            throw new RuntimeException("加密算法不存在", e);
        }
    }
}
